﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Shapes;

namespace AILabelTool.Expends
{
    public static class WindowStructExpend
    {

        /// <summary>
        /// 是否包含
        /// </summary>
        /// <param name="rect"></param>
        /// <param name="other"></param>
        /// <returns></returns>
        public static bool IsContains(this Rect rect, Rect other)
        {
            return Math.Min(rect.X, other.X) == rect.X &&
                Math.Min(rect.Y, other.Y) == rect.Y &&
                Math.Max(rect.X + rect.Width, other.X + other.Width) == rect.X + rect.Width &&
                Math.Max(rect.Y + rect.Height, other.Y + other.Height) == rect.Y + rect.Height;
        }
        /// <summary>
        /// 矩阵是否包含多边形
        /// </summary>
        /// <param name="rect"></param>
        /// <param name="polygon"></param>
        /// <returns></returns>
        public static bool IsContains(this Rect rect, Polygon polygon)
        {
            return rect.IsContains(polygon.GetPolygonWithRect());
        }
        /// <summary>
        /// 是否包含矩形
        /// </summary>
        /// <param name="rect"></param>
        /// <param name="rectangle"></param>
        /// <returns></returns>
        public static bool IsContains(this Rect rect, Rectangle rectangle)
        {
            return rect.IsContains(new Rect(Canvas.GetLeft(rectangle), Canvas.GetTop(rectangle), rectangle.Width, rectangle.Height));
        }
        /// <summary>
        /// 求出外接矩阵
        /// </summary>
        /// <param name="polygon"></param>
        /// <returns></returns>
        public static Rect GetPolygonWithRect(this Polygon polygon)
        {
            var point = new Point(Canvas.GetLeft(polygon), Canvas.GetTop(polygon));
            double maxx = 0;
            double maxy = 0;
            foreach (var item in polygon.Points)
            {
                var x = item.X + point.X;
                var y = item.Y + point.Y;

                if (x > maxx)
                {
                    maxx = x;
                }
                if (y > maxy)
                {
                    maxy = y;
                }
            }

            return new Rect(point.X, point.Y, maxx - point.X, maxy - point.Y);
        }

        /// <summary>
        /// 转换到arbg
        /// </summary>
        /// <param name="color"></param>
        /// <returns></returns>
        public static string ColorToHexARGB(this Color color)
        {
            return color.ToString();
        }
    }
}
